package com.kyxx.topics.bean;

import android.content.Context;

import com.kyxx.topics.utils.SharedPreferenceUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * @author Administrator 登录用户信息
 */
public class AppModel {

    /**
     * 当前帐号是否已经登录的标识
     */
    public static boolean is_login = false;

    private String username;// 用户名
    private String pwd;// 密码
    private String id;// 用户Id
    private String avatar;// 头像
    private String mobile;// 手机号
    private String nickname;// 用户昵称
    private String imgurl;//
    private String signature;//签名
    private String loginName;
    private String mode;
    private String oauth_qq_id;
    private String oauth_wx_id;
    private String deviceId;

    private static SharedPreferenceUtils utils;

    public static AppModel init(Context context) {
        AppModel model = new AppModel();
        utils = SharedPreferenceUtils.init(context);

        if (utils.getUsername() != null) {
            model.username = utils.getUsername();
        }
        if (utils.getNickname() != null) {
            model.nickname = utils.getNickname();
        }
        if (utils.getPwd() != null) {
            model.pwd = utils.getPwd();
        }

        if (utils.getId() != null) {
            model.id = utils.getId();
        }

        if (utils.getAvatar() != null) {
            model.avatar = utils.getAvatar();
        }

        if (utils.getMobile() != null) {
            model.mobile = utils.getMobile();
        }

        if (utils.getSignature() != null) {
            model.signature = utils.getSignature();
        }
        if (utils.getImgurl() != null) {
            model.imgurl = utils.getImgurl();
        }

        if (utils.getLoginName() != null) {
            model.loginName = utils.getLoginName();
        }

        if (utils.getMode() != null) {
            model.mode = utils.getMode();
        }
        if (utils.getOauth_qq_id() != null) {
            model.oauth_qq_id = utils.getOauth_qq_id();
        }
        if (utils.getOauth_wx_id() != null) {
            model.oauth_wx_id = utils.getOauth_wx_id();
        }
        if (utils.getDeviceId() != null) {
            model.deviceId = utils.getDeviceId();
        }
        return model;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
        utils.setUsername(username);
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
        utils.setNickname(nickname);
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        this.pwd = pwd;
        utils.setPwd(pwd);
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
        utils.setId(id);
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
        utils.setAvatar(avatar);
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
        utils.setMobile(mobile);
    }

    public String getImgurl() {
        return imgurl;
    }

    public void setImgurl(String imgurl) {
        this.imgurl = imgurl;
        utils.setImgurl(imgurl);
    }

    public String getSignature() {
        return signature;
    }

    public void setSignature(String signature) {
        this.signature = signature;
        utils.setSignature(signature);
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String signature) {
        this.loginName = loginName;
        utils.setLoginName(loginName);
    }

    public String getMode() {
        return mode;
    }

    public void setMode(String mode) {
        this.mode = mode;
        utils.setMode(mode);
    }

    public String getOauth_qq_id() {
        return oauth_qq_id;
    }

    public void setOauth_qq_id(String oauth_qq_id) {
        this.oauth_qq_id = oauth_qq_id;
        utils.setOauth_qq_id(oauth_qq_id);
    }

    public String getOauth_wx_id() {
        return oauth_wx_id;
    }

    public void setOauth_wx_id(String oauth_wx_id) {
        this.oauth_wx_id = oauth_wx_id;
        utils.setOauth_wx_id(oauth_wx_id);
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
        utils.setDeviceId(deviceId);
    }

    public void clear() {
        this.setUsername("");
        this.setNickname("");
        this.setPwd("");
        this.setId("");
        this.setAvatar("");
        this.setMobile("");
        this.setLoginName("");
        this.setMode("");
        this.setOauth_qq_id("");
        this.setOauth_wx_id("");
        ImageLoader.getInstance().clearDiskCache();
        ImageLoader.getInstance().clearMemoryCache();
        utils.clear();
    }
}
